package ro.ubbcluj.cs.validation.framework.tags;

import javax.servlet.jsp.tagext.BodyTagSupport;

import org.apache.commons.lang.StringUtils;

/**
 * <p>
 * <strong><code>BaseTag</code></strong> is the base class for all validation
 * framework JSP tags
 * </p>
 */

public abstract class BaseTag extends BodyTagSupport {

	private static final long serialVersionUID = 6751974138734589953L;

	// Core Attributes
	/**
	 * id - Specifies a unique id for an element
	 */
	private String htmlId;
	/**
	 * style_definition - Specifies an inline style for an element
	 */
	private String style;
	/**
	 * classname - Specifies a classname for an element
	 */
	private String styleClass;
	/**
	 * text - Specifies extra information about an element
	 */
	private String title;

	// Language Attributes
	/**
	 * ltr/rtl - Specifies the text direction for the content in an element
	 */
	private String dir;
	/**
	 * language_code - Specifies a language code for the content in an element
	 */
	private String lang;

	// Keyboard Attributes
	/**
	 * number - Specifies the tab order of an element
	 */
	private String tabindex;
	/**
	 * character - Specifies a keyboard shortcut to access an element
	 */
	private String accesskey;

	// Form events
	/**
	 * script - Script to be run when an element loses focus
	 */
	private String onblur;
	/**
	 * script - Script to be run when an element change
	 */
	private String onchange;
	/**
	 * script - Script to be run when an element gets focus
	 */
	private String onfocus;
	/**
	 * script - Script to be run when an element is selected
	 */
	private String onselect;

	// Keyboard events
	/**
	 * script - Script to be run when a key is pressed
	 */
	private String onkeydown;
	/**
	 * script - Script to be run when a key is pressed and released
	 */
	private String onkeypress;
	/**
	 * script - Script to be run when a key is released
	 */
	private String onkeyup;

	// Mouse events
	/**
	 * script - Script to be run on a mouse click
	 */
	private String onclick;
	/**
	 * script - Script to be run on a mouse double-click
	 */
	private String ondblclick;
	/**
	 * script - Script to be run when mouse button is pressed
	 */
	private String onmousedown;
	/**
	 * script - Script to be run when mouse pointer moves
	 */
	private String onmousemove;
	/**
	 * script - Script to be run when mouse pointer moves out of an element
	 */
	private String onmouseout;
	/**
	 * script - Script to be run when mouse pointer moves over an element
	 */
	private String onmouseover;
	/**
	 * script - Script to be run when mouse button is released
	 */
	private String onmouseup;
	
	protected String getAttributes() {
		StringBuilder sb = new StringBuilder();
		if (StringUtils.isNotEmpty(htmlId)) {
			sb.append("id=\""+htmlId+"\" ");
		}
		if (StringUtils.isNotEmpty(title)) {
			sb.append("title=\""+title+"\" ");		
		}
		if (StringUtils.isNotEmpty(styleClass)) {
			sb.append("class=\""+styleClass+"\" ");
		}
		if (StringUtils.isNotEmpty(style)) {
			sb.append("style=\""+style+"\" ");
		}
		if (StringUtils.isNotEmpty(dir)) {
			sb.append("dir=\""+dir+"\" ");
		}
		if (StringUtils.isNotEmpty(lang)) {
			sb.append("lang=\""+lang+"\" ");
		}
		if (StringUtils.isNotEmpty(tabindex)) {
			sb.append("tabindex=\""+tabindex+"\" ");
		}
		if (StringUtils.isNotEmpty(accesskey)) {
			sb.append("accesskey=\""+accesskey+"\" ");
		}
		if (StringUtils.isNotEmpty(onblur)) {
			sb.append("onblur=\""+onblur+"\" ");
		}
		if (StringUtils.isNotEmpty(onfocus)) {
			sb.append("onfocus=\""+onfocus+"\" ");
		}
		if (StringUtils.isNotEmpty(onchange)) {
			sb.append("onchange=\""+onchange+"\" ");
		}
		if (StringUtils.isNotEmpty(onselect)) {
			sb.append("onselect=\""+onselect+"\" ");
		}
		if (StringUtils.isNotEmpty(onclick)) {
			sb.append("onclick=\""+onclick+"\" ");
		}
		if (StringUtils.isNotEmpty(ondblclick)) {
			sb.append("ondblclick=\""+ondblclick+"\" ");
		}
		if (StringUtils.isNotEmpty(onkeydown)) {
			sb.append("onkeydown=\""+onkeydown+"\" ");
		}
		if (StringUtils.isNotEmpty(onkeyup)) {
			sb.append("onkeyup=\""+onkeyup+"\" ");
		}
		if (StringUtils.isNotEmpty(onkeypress)) {
			sb.append("onkeypress=\""+onkeypress+"\" ");
		}
		if (StringUtils.isNotEmpty(onmousedown)) {
			sb.append("onmousedown=\""+onmousedown+"\" ");
		}
		if (StringUtils.isNotEmpty(onmouseup)) {
			sb.append("onmouseup=\""+onmouseup+"\" ");
		}
		if (StringUtils.isNotEmpty(onmouseover)) {
			sb.append("onmouseover=\""+onmouseover+"\" ");
		}
		if (StringUtils.isNotEmpty(onmouseout)) {
			sb.append("onmouseout=\""+onmouseout+"\" ");
		}
		if (StringUtils.isNotEmpty(onmousemove)) {
			sb.append("onmousemove=\""+onmousemove+"\" ");
		}
		return sb.toString();
	}

	public String getHtmlId() {
		return htmlId;
	}

	public void setHtmlId(String htmlId) {
		this.htmlId = htmlId;
	}

	public String getStyle() {
		return style;
	}

	public void setStyle(String style) {
		this.style = style;
	}

	public String getStyleClass() {
		return styleClass;
	}

	public void setStyleClass(String styleClass) {
		this.styleClass = styleClass;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getDir() {
		return dir;
	}

	public void setDir(String dir) {
		this.dir = dir;
	}

	public String getLang() {
		return lang;
	}

	public void setLang(String lang) {
		this.lang = lang;
	}

	public String getTabindex() {
		return tabindex;
	}

	public void setTabindex(String tabindex) {
		this.tabindex = tabindex;
	}

	public String getAccesskey() {
		return accesskey;
	}

	public void setAccesskey(String accesskey) {
		this.accesskey = accesskey;
	}

	public String getOnblur() {
		return onblur;
	}

	public void setOnblur(String onblur) {
		this.onblur = onblur;
	}

	public String getOnchange() {
		return onchange;
	}

	public void setOnchange(String onchange) {
		this.onchange = onchange;
	}

	public String getOnfocus() {
		return onfocus;
	}

	public void setOnfocus(String onfocus) {
		this.onfocus = onfocus;
	}

	public String getOnselect() {
		return onselect;
	}

	public void setOnselect(String onselect) {
		this.onselect = onselect;
	}

	public String getOnkeydown() {
		return onkeydown;
	}

	public void setOnkeydown(String onkeydown) {
		this.onkeydown = onkeydown;
	}

	public String getOnkeypress() {
		return onkeypress;
	}

	public void setOnkeypress(String onkeypress) {
		this.onkeypress = onkeypress;
	}

	public String getOnkeyup() {
		return onkeyup;
	}

	public void setOnkeyup(String onkeyup) {
		this.onkeyup = onkeyup;
	}

	public String getOnclick() {
		return onclick;
	}

	public void setOnclick(String onclick) {
		this.onclick = onclick;
	}

	public String getOndblclick() {
		return ondblclick;
	}

	public void setOndblclick(String ondblclick) {
		this.ondblclick = ondblclick;
	}

	public String getOnmousedown() {
		return onmousedown;
	}

	public void setOnmousedown(String onmousedown) {
		this.onmousedown = onmousedown;
	}

	public String getOnmousemove() {
		return onmousemove;
	}

	public void setOnmousemove(String onmousemove) {
		this.onmousemove = onmousemove;
	}

	public String getOnmouseout() {
		return onmouseout;
	}

	public void setOnmouseout(String onmouseout) {
		this.onmouseout = onmouseout;
	}

	public String getOnmouseover() {
		return onmouseover;
	}

	public void setOnmouseover(String onmouseover) {
		this.onmouseover = onmouseover;
	}

	public String getOnmouseup() {
		return onmouseup;
	}

	public void setOnmouseup(String onmouseup) {
		this.onmouseup = onmouseup;
	}

	public void release() {
		super.release();
		this.htmlId = null;
		this.style = null;
		this.styleClass = null;
		this.title = null;

		this.dir = null;
		this.lang = null;

		this.tabindex = null;
		this.accesskey = null;

		this.onblur = null;
		this.onchange = null;
		this.onfocus = null;
		this.onselect = null;

		this.onkeydown = null;
		this.onkeypress = null;
		this.onkeyup = null;

		this.onclick = null;
		this.ondblclick = null;
		this.onmousedown = null;
		this.onmousemove = null;
		this.onmouseout = null;
		this.onmouseover = null;
		this.onmouseup = null;
	}

}
